<template>
  <!--招采管理-班组招采列表-修改弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :model="model" :rules="validatorRules">
      <!-- 主表单区域 -->
      <a-row class="form-row" :gutter="16">
        <a-col :lg="8">
          <a-form-model-item label="招标名称" required prop="name">
            <a-input v-model="model.name" placeholder="请输入招标名称" />
          </a-form-model-item>
        </a-col>
        <a-col :lg="8">
          <a-form-model-item label="所属项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="project">
            <a-select :options="levelOneOptions1" v-model="model.project"  placeholder="请选择项目"></a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="8">
          <a-form-model-item label="结标时间" prop="traneIncTime">
            <j-date showTime valueFormat="YYYY-MM-DD" v-model="model.traneIncTime" />
          </a-form-model-item>
        </a-col>
        <a-col :span="15" style="margin-right: -250px">
          <a-form-model-item label="技术要求(上传文件包)" prop="fileList">
            <j-upload v-model="model.technicalRequirements"></j-upload>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="6">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-button type="primary" @click="handleSupplier" icon="search" style="margin-left: 8px"
                >选择供应商</a-button
              >
            </a-form-model-item>
          </a-col> -->
      </a-row>

      <!-- 子表单区域 -->
      <a-tabs defaultActiveKey="1">
        <a-tab-pane tab="招标信息" key="1">
          <div>
            <a-row type="flex" style="margin-bottom: 10px" :gutter="16">
              <!-- <a-col :span="4">班组分类</a-col> -->
              <!-- <a-col :span="4">二级分类</a-col>
                <a-col :span="3">三级分类</a-col> -->
              <a-col :span="4">项目名称</a-col>
              <a-col :span="4">计量单位</a-col>
              <a-col :span="4">工程量</a-col>
              <a-col :span="4">综合单价</a-col>

              <a-col :span="4">合价</a-col>
              <a-col :span="1">操作</a-col>
            </a-row>

            <a-row
              type="flex"

              :gutter="16"
              v-for="(item, index) in model.biddingMaterialsList"
              :key="index"
            >
              <!-- <a-col :span="4">
          <a-form-model-item  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="constructionTeam">
              <j-dict-select-tag   dictCode="construction_team"  v-model="model.constructionTeam" placeholder="请输入分类名称" />


            </a-form-model-item>
          </a-col> -->

              <a-col :span="4">
                <a-form-model-item>
                  <a-form-model-item style="width: 160px" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
                    <a-input v-model="item.name" placeholder="请输入项目名称"></a-input>
                  </a-form-model-item>
                </a-form-model-item>
              </a-col>
              <!-- <a-col :span="3">

                    <a-form-model-item  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainProduct">
                <a-input v-model="model.mainProduct" placeholder="请输入施工范围"  ></a-input>
              </a-form-model-item>

                </a-col> -->
              <!-- <a-col :span="3">
                  <a-form-model-item>
                    <a-select
                      :options="StandardList"
                      v-model="item.platformProductId"
                      placeholder="物资名称"
                      @change="handleCheckedCitiesChange(item.platformProductId,index)"
                    ></a-select>
                  </a-form-model-item>
                </a-col> -->
              <!-- <a-col :span="3">
                  <a-form-model-item>
                    <a-select :options="modelList" v-model="item.model" placeholder="规格/型号"></a-select>
                  </a-form-model-item>
                </a-col> -->
              <a-col :span="4">
                <a-form-model-item>
                  <a-input v-model="item.unit" :options="unit" placeholder="计量单位"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-form-model-item>
                  <a-input v-model="item.num" placeholder="工程量"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-form-model-item>
                  <a-input v-model="item.price" placeholder="综合单价"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-form-model-item>
                  <a-input v-model="item.money" placeholder="合价"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="1">
                <a-form-model-item>
                  <a-icon type="minus-circle" @click="delRcruit(index)" style="fontsize: 20px" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-button type="dashed" style="width: 98%; margin-top: 10px" @click="addRcruit">
              <a-icon type="plus" /> 添加招标信息
            </a-button>
          </div>
        </a-tab-pane>
      </a-tabs>
    </a-form-model>
    <!-- <Wt-Public-Price-Supplier-Modal ref="modalForm2" @ok="modalFormOk"></Wt-Public-Price-Supplier-Modal> -->
  </a-spin>
</template>

  <script>
import { httpAction, getAction } from '@/api/manage'
import JDate from '@/components/jeecg/JDate'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { axios } from '@/utils/request'
import signMd5Utils from '@/utils/encryption/signMd5Utils'
// import WtPublicPriceSupplierModal from './WtPublicBiddingPriceSupplierModal.vue'
// import WtPublicPriceSupplierForm from './WtPublicBiddingPriceSupplierForm.vue'
export default {
  name: 'WtPublicBiddingRecruitForm',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,

    // MaterialSupplier,
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
    id: {
      type: String,
    },
  },
  data() {
    return {
      title: '操作',
      visible: false,
      id: '',
      treeData:[],
      levelOneOptions1:[],
      model: {
        name: '',
        project: '',
        traneIncTime: '',
        technicalRequirements: [],
        biddingMaterialsList: [
          {
            name: '',
            num: '',
            unit: '',
            price: '',
            money: '',
          },
        ],
      },

      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        name: [{ required: true, message: '招采名称不能为空', trigger: 'blur' }],
      },
      url: {
        add: '/bidding/wtPublicBidding/add',
        edit: '/bidding/wtPublicBidding/edit',
        orderCustomerList: '/test/jeecgOrderMain/queryOrderCustomerListByMainId',
        orderTicketList: '/test/jeecgOrderMain/queryOrderTicketListByMainId',
        list: '/bidding/wtPublicBiddingMaterials/queryList',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: { type: '1', publicBiddingId: this.id },

    }
  },
  created() {},
  methods: {



    add() {
      this.edit({})
    },
    edit(record) {
      // console.log('123', record);
      let url = "/bidding/wtPublicBiddingMaterials/queryList"
      let parameter = {
        publicBiddingId: record.id
      }

      let sign = signMd5Utils.getSign(url, parameter);

      let signHeader = { "X-Sign": sign, "X-TIMESTAMP": signMd5Utils.getTimestamp() };

      axios({
        url: url,
        method: 'get',
        params: parameter,
        headers: signHeader
      }).then((res) => {
        this.model.biddingMaterialsList = res.result


      })

      this.model = Object.assign(
        {
          biddingMaterialsList: [{}],
        },
        record
      )
      this.loadTree()
      this.visible = true

    },
    close() {
      this.$emit('close')
      this.visible = false
      this.loadTree()
    },
    loadTree() {
      var that = this
      getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
        if (res.success) {
          // console.log(res)
          that.treeData1 = []
          let treeList1 = res.result
          for (let a = 0; a < treeList1.length; a++) {
            let temp = treeList1[a]
            temp.isLeaf = temp.leaf
            that.treeData1.push(temp)
          }
          that.levelOneOptions1 = [...that.treeData1].map((v) => {
            return {
              ...v,
              value: v.id,
              label: v.departName,
            }
          })
          // console.log('项目1：', that.model)
          // console.log('项目2：', that.levelOneOptions1)
          let info = that.levelOneOptions1.filter(item => {
            return item.departName === that.model.project
          })
          that.model.project = info[0].value
          // console.log('项目3：', info)
          // console.log('that.model.project：', that.model.project)
        }
      })
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          var models=this.model
          this.imageUrl = getFileAccessHttpUrl(this.technicalRequirements)
          models.technicalRequirements= this.imageUrl
          // console.log('656',this.model);
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    addRcruit() {
      this.model.biddingMaterialsList.push({})

      this.$forceUpdate()
    },
    delRcruit(index) {
      this.model.biddingMaterialsList.splice(index, 1)
      this.$forceUpdate()
      this.model.biddingMaterialsList.model =
        this.model.biddingMaterialsList.num =
        this.model.biddingMaterialsList.unit =

        this.model.biddingMaterialsList.platformProductName =
          ''
    },
  },
}
</script>
  <style scoped>
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
.ant-form-item-control {
  line-height: 0px;
}
/** 主表单行间距 */
.ant-form .ant-form-item {
  /* margin-bottom: 10px; */
}
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>
